<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/tentime">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
    <style type="text/css">
        .layui-form-radio {margin: 0px 5px 0 0 !important;}
        .layui-input-block {margin-left: 0px!important;}
        .layui-upload-img{width:100px;height: 100px;}
        .logo-img{
            position: relative;
            margin: 0px auto;
            width: 200px;
            height: 200px;
            border-radius: 50%;
            overflow: hidden;
            border: 4px solid rgb(217, 221, 225);
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="layui-form tentime-compile">
    <form id="inputForm" class="layui-form">
        <input id="id" type="hidden" name="id" th:if="${entity}" th:value="${entity?.id}"/>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">租户标识</label>
                <div class="layui-input-inline">
                    <input class="layui-input" type="text" name="tenantId" placeholder="请输入租户标识" th:value="${entity.masterTenant.tenantId}" readonly = true>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label required">租户名称</label>
                <div class="layui-input-inline">
                    <input class="layui-input" lay-verify="required" type="text" name="tenantName" placeholder="请输入客户名称" th:value="${entity.masterTenant.tenantName}">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label required">租户简称</label>
                <div class="layui-input-inline">
                    <input class="layui-input" lay-verify="required" type="text" name="shortName" placeholder="请输入租户短名" th:value="${entity.masterTenant.shortName}">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">默认样式</label>
                <div class="layui-input-inline">
                    <select class="tentime-search-select" name="skin" mo:dict="SKIN_TYPE" mo-selected="${entity?.skin}" mo-empty="全部"></select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label required" style="width: 120px;">开启顶部导航</label>
                <div class="layui-input-inline">
                    <input type="radio" name="enableNav" value="0" title="否" checked>
                    <input type="radio" name="enableNav" value="1" title="是" th:checked="${entity?.enableNav} eq true">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">LOGO图片</label>
                <div class="layui-input-inline">
                    <!--
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" id="fileUpload">上传图片</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="logo" th:src="${ctxStatic} + ${entity?.logo}">
                        </div>
                    </div>
                    -->
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" id="fileUpload">上传图片</button>
                        <div class="layui-upload-list">
                            <span th:if="${#strings.isEmpty(entity.logo)}">
                                <img id="logo" class="logo-img" th:src="@{/images/logo_default.jpg}" alt="头像" style="width:200px;">
                            </span>
                            <span th:if="${not #strings.isEmpty(entity.logo)}">
                                <img id="logo" class="logo-img" th:src="${ctxStatic} + ${entity?.logo}" alt="头像" style="width:200px;">
                            </span>
                        </div>
                    </div>
                    <!--
                    <div class="user-avatar-box">
                        <span th:if="${#strings.isEmpty(entity.logo)}">
                            <img class="user-avatar logo-img" th:src="@{/images/logo_default.jpg}" alt="头像" style="width:200px;">
                        </span>
                        <span th:if="${not #strings.isEmpty(entity.logo)}">
                            <img class="user-avatar" th:src="${ctxStatic} + ${entity?.logo}" alt="头像" style="width:200px;">
                        </span>
                        <span class="edit-avatar" th:attr="data-url=@{/userPicture}">修改头像</span>
                    </div>
                    -->
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-inline" style="width: 603px;!important;">
                    <textarea id="remarks" name="remarks" th:utext="${entity?.remarks}" style="display: none;"></textarea>
                </div>
            </div>
        </div>
        <div class="layui-form-item tentime-finally">
            <button class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="submit_button" shiro:hasAnyPermissions="masterTenat:setting"><i class="fa fa-check-circle"></i> 保存</button>
            <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="closeTab();" type="button"><i class="fa fa-times-circle"></i> 关闭</button>
        </div>
    </form>

</div>
<script th:replace="/common/template :: common"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['form','layer','layedit', 'jquery','upload',"element"], function () {
        window.form = layui.form;
        layer = layui.layer, $ = layui.jquery, layedit = layui.layedit, upload = layui.upload, element = layui.element;
        //富文本设置
        var index = layedit.build('remarks', {
            tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right','|', 'table', 'fullScreen', 'preview'],
            height: 80
        });
        //表单提交
        form.on("submit(submit_button)", function (data) {
            var content = layedit.getContent(index);
            $('#remarks').text(content);
            $("#inputForm").ajaxSubmit({
                type : "post"
                ,url : ctx + '/masterTenantDetail/saveEntity'
                /*,data: {'refId': refId}*/
                ,success : function(data) {
                    var code = data.code;
                    if (code == 200) {
                        //parent.layer.msg('数据保存成功!', {icon: 1});
                        //closeWin();
                        //window.parent.reloadTable();
                        layer.msg('数据保存成功!', {icon: 1});
                        setTimeout(function () {closeTab();}, 2000);
                    } else {
                        //parent.layer.msg('数据验证失败!', {icon: 2});
                        layer.msg('数据验证失败!', {icon: 2});
                    }
                }
            });
            return false;
        });
        // 直接上传图片
        var uploadInst = upload.render({
            elem: '#fileUpload'
            ,url: ctx + '/masterTenant/uploadLogo'
            ,exts: 'jpg|png|gif|jpeg'
            ,data: {'refId': $('#id').val()}
            ,auto: true
            // 选择文件回调
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#logo').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res, index) {
                if (res.code == 400) {
                    layer.msg('数据验证失败!', {icon: 2});
                }
            }
        });

    });

</script>
</body>
</html>